<?php
session_start();
?>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        include 'functions.php';
        $confID = $_GET['conference_id'];
        $cfp = $_GET['callforpapers'];
        $confName = get_conference_name($confID);
        print "<h1>{$confName}</h1><br>
            <h2>Please select users to send this call for papers to:</h2><br>";


        echo '<table>
            <tr>
            <td>';
        // an array of alphabets
        $alphabets = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'
            , 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
        for ($i = 0; $i <= 25; $i++) { // loop on the 25 letters in the array
            $Letter = $alphabets[$i]; //save each letter in a variable 
            // make the letters links and when clicked it should send an ajax request to this page passing it the clicked letter   
            echo '<a href="#" onclick="javascript:AjaxRequest(this);">' . $Letter . '</a>&nbsp;';
        }
        echo '</td>
            </tr><tr>
            <td>
        <div id="mydiv">

        </div>
            </td></tr>
</table>';
        // save the conference id in a variable 
        // put the conference id in hidden input to get it in the javascript code in this page 
        echo '<input type="hidden" name="conference_id" id="conference_id" value="' . $confID . '"/> ';
        echo '<input type="hidden" name="callForPapers" id="callForPapers" value="' . $cfp . '"/> ';
        // }
        ?> 



    </body>
</html>
<head>
    <?php include "jquery.php"; ?>
    <script language="javascript">
                    
        // when a link letter is clicked, this code sends to inviteOrganizers page that 
        //loads in this page's div element the conference id and the clicked letter
        $(document).ready(function()
        {
            conferenceID = $("#conference_id").val();
            $.ajax({
                type:"POST",
                url: "mailingList.php",
                data:{
                    letter:"A",
                    conference_id:conferenceID
                },
                success: function(response)
                {
                    document.getElementById("mydiv").innerHTML = response;
                }
            });
                
            $("a").bind("click", function()
            {
                clicked_letter=$(this).html();
                    
                $.ajax({
                    type:"POST",
                    url: "mailingList.php",
                    data:{
                        letter:clicked_letter,
                        conference_id:conferenceID
                    },
                    success: function(response)
                    {
                        document.getElementById("mydiv").innerHTML = response;
                    }
                });
            });
                
        });
			
	
        function sendCallforPapers()
        {
            members=[];
            conferenceID = $("#conference_id").val();
            callforpapers = $("#callForPapers").val();
            $("input[type=checkbox]:checked").each(function()
            {
                member=$(this).val();
                members[members.length]=member;
            });
            $.ajax({
                type:"POST",
                url:"mailingList.php",
                data:{
                    member_ids:members,
                    conference_id:conferenceID,
                    cfp:callforpapers
                },
                success:function(response)
                {
                    $("#mydiv").fadeOut(300,function()
                    {
                        $("#mydiv").html(response);
                        $("#mydiv").fadeIn(300);
                    });
                }
            }
        );
        }
    </script>
</head>
